var status = -1;
var selectionLog = [];

function action(d, c, b) {
    if (status == 0 && d == 0) {
        cm.dispose();
        return
    }
    status++;
    selectionLog[status] = b;
    var a = -1;
    if (status <= a++) {
        cm.dispose()
    } else {
        if (status === a++) {
            cm.onActionBarResult(15, 1010, 0, 3, 0);
            cm.onActionBarResult(15, 1010, 0, 3, 1);
            cm.onActionBarResult(15, 1010, 0, 3, 2);
            cm.onActionBarResult(15, 1010, 0, 3, 3);
            cm.onActionBarResult(15, 1010, 0, 3, 4);
            cm.onActionBarResult(5, 1010);
            cm.teachSkill(80011562, 1, 1);
            cm.teachSkill(80011565, 1, 1);
            cm.teachSkill(80011561, 1, 1);
            cm.teachSkill(80011567, 1, 1);
            cm.teachSkill(80011641, 1, 1);
            cm.updateInfoQuest(64001, "dir1=0;man=720;stage=0;enemy=401253;seq=0;mine=0;companion=108372654;dir0=0");
            cm.addPopupSay(9400602, 10000, "#face1##h0#，我负责的部分我一定会想办法拦住的……毕竟我可是凯恩骑士的大弟子！", "", 0);
            nextBattle(0);
            cm.dispose()
        }
    }
}

function nextBattle(g) {
    for (var k = [], f = 0, e = 0; e <= 5; ++f, ++e) {
        if (cm.getInfoQuest(10006400).contains("mob" + e + "=1")) {
            continue
        }
        k[f] = e
    }
    var l = k.sort(function () {
        return Math.random() - 0.5
    });
    for (var k = [], f = 0, e = 0; e <= 8; ++f, ++e) {
        if (cm.getInfoQuest(10006400).contains("npc" + e + "=1")) {
            continue
        }
        k[f] = e
    }
    var h = k.sort(function () {
        return Math.random() - 0.5
    });
    var d = cm.rand(30, 150);
    var c = cm.rand(30, 150);
    var b = cm.rand(30, 150);
    cm.setNumberForQuestInfo(64002, "man", d);
    cm.setNumberForQuestInfo(64003, "man0", c);
    cm.setNumberForQuestInfo(64003, "man1", b);
    cm.莫奈德_特效(null, [2, g, l[0], h[0], d, g, l[1], h[1], c, g, l[2], h[2], b])
}

function start() {
    status = -1;
    action(1, 0, 0)
};